<?php
/**
 * @author Martin Pernica
 * @copyright 2008
 */
require '../libs/hash.php';
echo '<h2>' . Lang::getBack('com_user', 'admin') . '</h2><div>';

if (empty($_GET['a'])) {
    $query = $db->query("SELECT * FROM {prefix}users ORDER BY created DESC LIMIT 50");

    echo '<p><a href="' . $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'] .
        '&a=usearch">' . Lang::getBack('com_user', 'search') . '</a></p>';

    echo '<table cellspacing="20" cellpadding="30" class="clean_table">';
    echo '<tr><th>' . Lang::getFront('com_user', 'nickname') . '</th><th>' . Lang::
        getFront('com_user', 'display_name') . '</th><th>' . Lang::getFront('com_user',
        'email') . '</th><th>' . Lang::getFront('com_user', 'rank') . '</th><th>' . Lang::
        getBackGlobal('action') . '</th></tr>';
    while ($data = $query->fetch_array()) {
        echo '<tr><td>' . $data['username'] . '</td><td>' . $data['display_name'] .
            '</td><td>' . $data['email'] . '</td><td>' . $data['rank'] .
            '</td><td><a href="' . $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'] .
            '&a=delete&id=' . $data['id'] .
            '"><img src="../libs/icons/delete.png" /></a>&nbsp;&nbsp;<a href="' . $_SERVER['PHP_SELF'] .
            '?' . $_SERVER['QUERY_STRING'] . '&a=edit&id=' . $data['id'] .
            '"><img src="../libs/icons/style_edit.png" /></td></tr>';
    }
    echo '</table>
<p>' . Lang::getBack('com_user', 'show_only', array(50)) . '</p>
</div><br />';
    unset($query, $data);
    echo '<h2>'.Lang::getBack('com_user', 'groups').'</h2><div>';
    echo '<p><a href="' . $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'] .
        '&a=gnew">'.Lang::getBack('com_user', 'group_new').'</a></p>';
    
    $query = $db->query("SELECT * FROM {prefix}users_groups ORDER BY id DESC");

    echo '<table cellspacing="20" cellpadding="30" class="clean_table">';
    echo '<tr><th>'.Lang::getBack('com_user', 'group_name').'</th><th>'.Lang::getBack('com_user', 'group_desc').'</th><th>'.Lang::getBackGlobal('action').'</th></tr>';
    while ($data = $query->fetch_array()) {
        echo '<tr><td>' . $data['name'] . '</td><td>' . $data['description'] .
            '</td><td><a href="' . $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'] .
            '&a=gdelete&id=' . $data['id'] .
            '"><img src="../libs/icons/delete.png" /></a>&nbsp;&nbsp;<a href="' . $_SERVER['PHP_SELF'] .
            '?' . $_SERVER['QUERY_STRING'] . '&a=gedit&id=' . $data['id'] .
            '"><img src="../libs/icons/style_edit.png" /></td></tr>';
    }
    echo '</table>';

} else {
    switch ($_GET['a']) {
        case 'new':
            require 'new.php';
            break;

        case 'delete':
            require 'delete.php';
            break;

        case 'edit':
            require 'edit.php';
            break;

        case 'usearch':
            require 'usearch.php';
            break;

        case 'gnew':
            require 'gnew.php';
            break;

        case 'gdelete':
            require 'gdelete.php';
            break;

        case 'gedit':
            require 'gedit.php';
            break;

        case 'fields':
            require 'fields.php';
            break;

        case 'fields-edit':
            require 'fields_edit.php';
            break;

        case 'fields-delete':
            require 'fields_delete.php';
            break;

        case 'fields-new':
            require 'fields_new.php';
            break;

        case 'fields-cat-new':
            require 'fields_cat_new.php';
            break;

        case 'fields-cat-edit':
            require 'fields_cat_edit.php';
            break;

        case 'fields-cat-delete':
            require 'fields_cat_delete.php';
            break;

    }
}
echo '</div>';
?>